<%@ page  pageEncoding="UTF-8"%>
<%@ page import = "java.util.*" %>
<%@ page import = "java.awt.*" %> 
<%@ page import = "com.synchrobit.synchroflow.enactmentservice.processmonitor.*" %>
<%@ page import="com.synchrobit.synchroflow.api.util.RMIManager"  %>
<%@ page import="com.synchrobit.synchroflow.api.web.PropertyServiceBean" %>
<%@ page import="com.synchroflow.common.*"  %>
<%@ page import="com.synchrobit.synchroflow.api.util.StringTools" %>
<%@ page import="com.synchroflow.orgInterface.OrgManager"  %>
<%@ page import="com.synchrobit.synchroflow.organization.orgClass.User" %>

<html>
<head>
<title>
<%=I18NTools.getString("com.synchroflow.frame.resource","jpgView_title")%>
</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<meta name="Microsoft Border" content="none">
<link rel="stylesheet" href="style/newobrs_style_001.css">
<link href="total.css" rel="stylesheet" type="text/css">
<style type=text/css>
td,div  { font: normal 12px; }
.menu_board  { background-color: #CCCCCC; width: 82px; border-top: 2px solid white; padding: 2px; }  
.menu_normal  { background-color: #CCCCCC; border: 1px solid #CCCCCC; }  
.menu_over  { cursor: hand; background-color: #DDDDDD; border: 1px solid #999999; }  
</style>
<link href="../../../css/total.css" rel="stylesheet" type="text/css">
</head>

<%
String contextPath=request.getContextPath();
//ReadXmlConfig confg=ReadXmlConfig.getInstance();
//String enactmentAPI ="rmi://127.0.0.1:8020/monitormi";
//String enactmentAPI =confg.getMonitorrimi();
//out.println(enactmentAPI);
%>
<body>

<%!
        /*OrgManager orgManager=new OrgManager();
		 User curUser=orgManager.getUser(Integer.parseInt(participant[i]));
		  if (curUser!=null)
		  {
		  	participant[i]=curUser.getUname();
		  }*/
		  
        public int[] getPoint(String restLine) {
        StringTokenizer st = new StringTokenizer(restLine, ",");
        
        int[] point = new int[2];
        int i = 0;
        while (st.hasMoreElements()) {
            String pos = st.nextToken();
            point[i] = Integer.parseInt(pos);
            i++;

        }

        return point;

    }
%>

<%!
       public int[][] modifyPoint(int[][] point) {
        int newPoint[][] = new int[2][];
        int[] ToPoint = new int[2];
        int[] FromPoint = new int[2];
  
        int step = 18;
        int fromX = point[0][0];
        int toX = point[1][0];
        int fromY = point[0][1];
        int toY = point[1][1];

        int mNewToX = 0;
        int mNewFromX = 0;
        int mNewToY = 0;
        int mNewFromY = 0;

        if (toY == fromY) { 
            if (toX > fromX) { 
                mNewToX = toX - step;
                mNewToY = toY;
                mNewFromX = fromX + step;
                mNewFromY = fromY;
            } else { 
                mNewToX = toX + step;
                mNewToY = toY;
                mNewFromX = fromX - step;
                mNewFromY = fromY;

            }
        }

        else if (toX == fromX) { 

            if (toY > fromY) { 
                mNewToY = toY - step;
                mNewToX = toX;
                mNewFromY = fromY + step;
                mNewFromX = fromX;

            } else { 
                mNewToY = toY + step;
                mNewToX = toX;
                mNewFromY = fromY - step;
                mNewFromX = fromX;

            }

        }

        else {

            double k = (double) (toY - fromY) / (double) (toX - fromX);
            if (k > 0 && toX > fromX) { 
                
                int newToX = toX - fromX;
                int newToY = toY - fromY;
                
                double tranLength = Math.sqrt(newToX * newToX + newToY * newToY);
                

                double ty0 = (((tranLength - step) / tranLength) * newToY);
                double tx0 = Math.sqrt((tranLength - step) * (tranLength - step) -
                                       ty0 * ty0);

                

                double fy0 = ((step / tranLength) * newToY);
                double fx0 = Math.sqrt(step * step - fy0 * fy0);

                
                mNewFromX = (int) (fx0 + fromX);
                mNewFromY = (int) (fy0 + fromY);
                mNewToX = (int) (tx0 + fromX);
                mNewToY = (int) (ty0 + fromY);

            } else if (k > 0 && toX < fromX) { 
                
                int newFromX = fromX - toX;
                int newFromY = fromY - toY;
                
                double tranLength = Math.sqrt(newFromX * newFromX +
                                              newFromY * newFromY);

                

                double ty0 = ((step / tranLength) * newFromY);
                double tx0 = Math.sqrt(step * step - ty0 * ty0);

               

                double fy0 = (((tranLength - step) / tranLength) * newFromY);
                double fx0 = Math.sqrt((tranLength - step) * (tranLength - step) -
                                       fy0 * fy0);

                
                mNewFromX = (int) (fx0 + toX);
                mNewFromY = (int) (fy0 + toY);
                mNewToX = (int) (tx0 + toX);
                mNewToY = (int) (ty0 + toY);

            } else if (k < 0 && toX > fromX) { 

                
                int newToX = toX - fromX;
                int newToY = 0;
                int newFromY = fromY - toY;
                int newFromX = 0;
                
                double tranLength = Math.sqrt(newFromY * newFromY +
                                              newToX * newToX);
                

                double ty0 = ((step / tranLength) * newFromY);
                double tx0 = newToX - Math.sqrt(step * step - ty0 * ty0);

                

                double fy0 = (((tranLength - step) / tranLength) * newFromY);
                double fx0 = newToX -
                             Math.sqrt((tranLength - step) * (tranLength - step) -
                                       fy0 * fy0);

                
                mNewFromX = (int) (fx0 + fromX);
                mNewFromY = (int) (fy0 + toY);
                mNewToX = (int) (tx0 + fromX);
                mNewToY = (int) (ty0 + toY);
            } else if (k < 0 && toX < fromX) { 

                
                int newToX = 0;

                int newToY = toY - fromY;
                int newFromY = 0;
                int newFromX = fromX - toX;
                
                double tranLength = Math.sqrt(newFromX * newFromX +
                                              newToY * newToY);
                

                double tx0 = ((step / tranLength) * newFromX);
                double ty0 = newToY - Math.sqrt(step * step - tx0 * tx0);

                

                double fx0 = (((tranLength - step) / tranLength) * newFromX);
                double fy0 = newToY -
                             Math.sqrt((tranLength - step) * (tranLength - step) -
                                       fx0 * fx0);

                
                mNewFromX = (int) (fx0 + toX);
                mNewFromY = (int) (fy0 + fromY);
                mNewToX = (int) (tx0 + toX);
                mNewToY = (int) (ty0 + fromY);

            }

        }
        ToPoint[0] = mNewToX;
        ToPoint[1] = mNewToY;
        FromPoint[0] = mNewFromX;
        FromPoint[1] = mNewFromY;
        newPoint[0] = FromPoint;
        newPoint[1] = ToPoint;

        return newPoint;

    }
%>
<%!
      Vector x0pos=new Vector();
	  Vector y0pos=  new Vector();
	  Vector x1pos=new Vector();
	  Vector y1pos=  new Vector();
	  Vector trans_id=  new Vector();
	  Vector trans_name= new Vector();

      public void drawTra( String transdefID,String name,
                         int[][] linePoint, int i) {
	

        if (i != 4) { 
		 int[][] newPoint = modifyPoint(linePoint);

		x0pos.add(new Integer(newPoint[0][0]));
		y0pos.add(new Integer(newPoint[0][1]));
		x1pos.add(new Integer(newPoint[1][0]));
	    y1pos.add(new Integer(newPoint[1][1]));
		trans_id.add(transdefID);
        trans_name.add(name);
	  } 
		  
		  else if (i == 4) { 

            int[][] newLinePoint = { {linePoint[0][0], linePoint[0][1]},
                                   {linePoint[1][0], linePoint[1][1]}
            };
            int[][] newPoint = modifyPoint(newLinePoint);
            x0pos.add(new Integer(newPoint[0][0]));
			y0pos.add(new Integer(newPoint[0][1]));
			x1pos.add(new Integer(newPoint[1][0]));
		    y1pos.add(new Integer(newPoint[1][1]));
			trans_id.add(transdefID);
            trans_name.add(name);
         }
    }
 
 %>



<%
 
    String fw=request.getParameter("fw");
    if(fw==null||fw.length()<0||fw.equals("")||fw.equals("null"))
	{
   
    }
    else
	{
		String  workitem_id_temp =request.getParameter("workitem_id");
		int workitem_id = Integer.parseInt(workitem_id_temp);
		try
		{   
		
		//	  ProcessMonitor pm = MonitorConnection.getProcessMonitor(enactmentAPI);
			 ProcessMonitor pm= RMIManager.getInstance().getPmRmiConnection();
			  pm.completeWorkItem(workitem_id);
			  out.println("<script type=\"text/javascript\">"); 
			  out.println("alert('"+I18NTools.getString("com.synchroflow.frame.resource","jpgView_done")+"');window.close();");
			  out.println("</script>");
		 } 
		 catch (Exception e) 
		{
			System.out.println(I18NTools.getString("com.synchroflow.frame.resource","complete_work_err")+e);
		}
    
    }

%>


<%    

       String fun=request.getParameter("fun");
        if(fun==null||fun.length()<0||fun.equals("")||fun.equals("null"))
		{
		}
		else
		{
        String activityIns_Id = request.getParameter("activityInsId");
        
		int activityInsId=0;

		if(activityIns_Id!=null){
		
		  activityInsId = Integer.parseInt(activityIns_Id);
		}
       
		String userName=request.getParameter("userName");


       if(fun.equals("c")){
		
		try{   
		//	  ProcessMonitor pm = MonitorConnection.getProcessMonitor(enactmentAPI);
		 		ProcessMonitor pm= RMIManager.getInstance().getPmRmiConnection();
			  pm.completeActivity(activityInsId,userName);
			  out.println("<script type=\"text/javascript\">"); 
              out.println("alert('"+I18NTools.getString("com.synchroflow.frame.resource","jpgView_ok")+"');window.close();");
		      out.println("</script>");
  
		  } 
	 
		 catch (Exception e) 
		{
			System.out.println(I18NTools.getString("com.synchroflow.frame.resource","complete_act_err")+e);
		}
			
	  }

		   if(fun.equals("s")){
			
			try{   
	//		  ProcessMonitor pm = MonitorConnection.getProcessMonitor(enactmentAPI);
			   ProcessMonitor pm= RMIManager.getInstance().getPmRmiConnection();
			  pm.suspendActivity(activityInsId,userName);
              out.println("<script type=\"text/javascript\">"); 
              out.println("alert('"+I18NTools.getString("com.synchroflow.frame.resource","jpgView_hune")+"');window.close();");
		      out.println("</script>");
				  
			  } 
		 
			 catch (Exception e) 
			{
				 System.out.println(I18NTools.getString("com.synchroflow.frame.resource","putup_act_err")+e);
				
			}
				
		  }

		  if(fun.equals("r")){
				
				try{   
		//		 ProcessMonitor pm = MonitorConnection.getProcessMonitor(enactmentAPI);
				 ProcessMonitor pm= RMIManager.getInstance().getPmRmiConnection();
				 pm.resumeActivity(activityInsId,userName);
				 out.println("<script type=\"text/javascript\">"); 
                 out.println("alert('"+I18NTools.getString("com.synchroflow.frame.resource","jpgView_reset")+"');window.close();");
		         out.println("</script>");
					  
				  } 
			 
				 catch (Exception e) 
				{
					System.out.println(I18NTools.getString("com.synchroflow.frame.resource","comeback_act_err")+e);
				}
					
			  }
         if(fun.equals("st")){
				
			try{   
		    
              String id=request.getParameter("processInsId");
            
			  int processInsId = Integer.parseInt(id);
            
			  String activity_id=request.getParameter("activityDefid");

			  int activityDefid = Integer.parseInt(activity_id);
           
			  int flowId=0;

			//	 ProcessMonitor pm = MonitorConnection.getProcessMonitor(enactmentAPI);
				 ProcessMonitor pm= RMIManager.getInstance().getPmRmiConnection();
				 pm.startActivity(processInsId,activityDefid,flowId,userName);
				 out.println("<script type=\"text/javascript\">");
                 out.println("alert('"+I18NTools.getString("com.synchroflow.frame.resource","jpgView_start")+"');window.close();");
		         out.println("</script>");
				 } 
			 
				 catch (Exception e) 
				{
					System.out.println(I18NTools.getString("com.synchroflow.frame.resource","start_act_err")+e);
				}
					
			  }


		  if(fun.equals("t")){
				
				try{   
		//		ProcessMonitor pm = MonitorConnection.getProcessMonitor(enactmentAPI);
				 ProcessMonitor pm= RMIManager.getInstance().getPmRmiConnection();
				pm.terminateActivity(activityInsId,userName);
				out.println("<script type=\"text/javascript\">"); 
                out.println("alert('"+I18NTools.getString("com.synchroflow.frame.resource","jpgView_end")+"');window.close();");
		        out.println("</script>");
					  
				  } 
			 
				 catch (Exception e) 
				{
					System.out.println(I18NTools.getString("com.synchroflow.frame.resource","terminate_act_err")+e);
				}
					
			  }


    }




%>

<%
     
      String userName=request.getParameter("userName");
      String processInsId=request.getParameter("processInsId");

      String over="";

      String process_name="";
	  String start_man="";
      int id=0; 

      if(processInsId!=null){
      id = Integer.parseInt(processInsId);
      }

      try{
//      ProcessMonitor pm = MonitorConnection.getProcessMonitor(enactmentAPI);
		 ProcessMonitor pm= RMIManager.getInstance().getPmRmiConnection();
		
      String pIns[] = pm.getProcessInsObject(id);

      
      process_name = pIns[0]; 
	  start_man = pIns[4]; 
		   
	 }  
	 catch (Exception e) {}
	 String State=request.getParameter("St");
	  String flag=request.getParameter("f");

       if(State==null){

		}
      else   
     {
		
		 if(flag==null){
		 
		 }
     else{
	 
	  if(flag.equals("1"))
	    {
		if(State.equals("1")||State.equals("2"))
		
		{ 
          
		  try
			  {   
	//	      ProcessMonitor pm = MonitorConnection.getProcessMonitor(enactmentAPI);
			 ProcessMonitor pm= RMIManager.getInstance().getPmRmiConnection();
              pm.suspendProcess(id,userName);
              out.println("<script type=\"text/javascript\">"); 
              out.println("alert('"+I18NTools.getString("com.synchroflow.frame.resource","jpgView_huneok")+"')");
		      out.println("</script>");
          } 
	        catch (Exception e) 
			{
		     out.println("<script type=\"text/javascript\">"); 
             out.println("alert('"+I18NTools.getString("com.synchroflow.frame.resource","a_exception")+e+"')");
		     out.println("</script>");
			
            }

	    }
        else 
		{
          out.println("<script type=\"text/javascript\">"); 
          out.println("alert('"+I18NTools.getString("com.synchroflow.frame.resource","jpgView_huning")+"')");
		  out.println("</script>");
        }

	 }

    if(flag.equals("2"))
		 
	 
	 {
		if(State.equals("3"))
		{ 
          
		  try
			  {
			  
		//      ProcessMonitor pm = MonitorConnection.getProcessMonitor(enactmentAPI);
			 ProcessMonitor pm= RMIManager.getInstance().getPmRmiConnection();
              pm.resumeProcess(id,userName);
		      out.println("<script type=\"text/javascript\">"); 
              out.println("alert('"+I18NTools.getString("com.synchroflow.frame.resource","jpgView_doneok")+"')");
			  out.println("</script>");
             } 
	        catch (Exception e) 
			{
		     out.println("<script type=\"text/javascript\">"); 
             out.println("alert('"+I18NTools.getString("com.synchroflow.frame.resource","a_exception")+e+"')");
		     out.println("</script>");
            }

	    }
       else 
		{
          out.println("<script type=\"text/javascript\">"); 
          out.println("alert('"+I18NTools.getString("com.synchroflow.frame.resource","jpgView_doneno")+"')");
		  out.println("</script>");
        }

	 }

	 if(flag.equals("3"))
	   {
		if(State.equals("1")||State.equals("2"))
		{ 
          
		  try
			  {   
		//      ProcessMonitor pm = MonitorConnection.getProcessMonitor(enactmentAPI);
			 ProcessMonitor pm= RMIManager.getInstance().getPmRmiConnection();
              pm.terminateProcess(id,userName);
			  over="over";
              System.out.println(I18NTools.getString("com.synchroflow.frame.resource","jpgView_endok")+id);
              out.println(I18NTools.getString("com.synchroflow.frame.resource","jpgView_return")+"<br>");
			  
		     } 
	        catch (Exception e) 
			{
			  out.println(I18NTools.getString("com.synchroflow.frame.resource","a_exception")+e);
		     
            }

	    }
       else 
		{
         out.println("<script type=\"text/javascript\">"); 
         out.println("alert('"+I18NTools.getString("com.synchroflow.frame.resource","jpgView_endno")+"')");
		 out.println("</script>");
        }

	 }
	 
}


}
 
     
      if(over.equals("over")){
	  
	  }
	  else{
	  
	   try{  

		  //if(State==null){
			   
	//	  ProcessMonitor pm =  MonitorConnection.getProcessMonitor(enactmentAPI);
		 ProcessMonitor pm= RMIManager.getInstance().getPmRmiConnection();
		  String pIns[] = pm.getProcessInsObject(id); 
		  State = (String)pIns[5].trim();
		 
		  } 
		  
         //}
            
         catch (Exception e) {
		 System.out.println(I18NTools.getString("com.synchroflow.frame.resource","get_state_err")+e);
         }
            if(State!=null){
            String s=State;
			
			if(State.equals("1")){
			s=I18NTools.getString("com.synchroflow.frame.resource","jpgView_init");
			}
			if(State.equals("2")){
			s=I18NTools.getString("com.synchroflow.frame.resource","jpgView_active");
			}
			if(State.equals("3")){
			s=I18NTools.getString("com.synchroflow.frame.resource","jpgView_hune");
			}
			if(State.equals("4")){
			s=I18NTools.getString("com.synchroflow.frame.resource","jpgView_over");
			}
			if(State.equals("5")){
			s=I18NTools.getString("com.synchroflow.frame.resource","jpgView_stop");
			}

			%>
			<p align="left"><strong ><font size="4"><%=I18NTools.getString("com.synchroflow.frame.resource","jpgView_title_tu")%></font></strong></p>
         
			<%}}%>
			
<%
if(!over.equals("over")){%>
<table class="TableBody" border="0"  >
<tr valign="bottom">
<td>
<table border="0" cellpadding="0" cellspacing="0" bordercolor="#99C1EE" class="TableBody">
<%
	///////////////////////////////modified by Yuan Dapeng

//	ProcessMonitor mPM = MonitorConnection.getProcessMonitor(enactmentAPI);
	 ProcessMonitor mPM= RMIManager.getInstance().getPmRmiConnection();
	String mIp=request.getServerName();
	String mPort=String.valueOf(request.getServerPort());
	String sId=processInsId;

	String[][] many=mPM.getMultiIPAndID(mIp,sId,mPort);
	
	if(many!=null){
		for(int i=0;i<many.length;i++){
	    String oneId=many[i][1];
	    String string="http://"+many[i][0]+":"+many[i][2]+contextPath;
	    System.out.println(string);
	%>	
			<tr valign="bottom">
			<td>
			<img border="1" usemap="#Map" name="images1"   style="border-color:'#99C1EE'" 
			src="<%=string%>/MonitorServerlet?pinsId=<%=oneId%>&name=<%=userName%>">
			</td>
			</tr>
	<%}
	}else{
	%>
		<tr valign="bottom">
			<td>
			<img border="1" usemap="#Map" name="images1"   style="border-color:'#99C1EE'" 
			src="<%=contextPath%>/MonitorServerlet?pinsId=<%=processInsId%>&name=<%=userName%>">
			</td>
			</tr>
	<%
	
	}
 ////////////////////////////////end by Yuan Dapeng
%>

</table>
</td>
<td>
<table vspace="bottom" class="TableBody" border="0" >
<tr valign="bottom">
<td  height='20' colspan='2'  bgcolor="#76EF5E" bordercolor="#76EF5E" width="50" ><%=I18NTools.getString("com.synchroflow.frame.resource","com_state")%></td>
</tr>
<tr valign="bottom"><td  height='20'    bgcolor="#C53712" bordercolor="#C53712" width="50"><%=I18NTools.getString("com.synchroflow.frame.resource","run_state")%></td></tr>
<tr valign="bottom"><td  height='20'   bgcolor="#375C90" bordercolor="#375C90"  width="60"><%=I18NTools.getString("com.synchroflow.frame.resource","un_run_state")%></td></tr>
</table>
</td>
</tr>
</table>
<table width="31%"  border="0" align="center" cellpadding="0" cellspacing="0">
    <tr align="center">
      <td width="25%"><input type="button" id="big"  name="big" value="<%=I18NTools.getString("com.synchroflow.frame.resource","jpgView_big")%>" onclick="big()"></td>
      <td width="25%"><input type="button" id="small" name="small" value="<%=I18NTools.getString("com.synchroflow.frame.resource","jpgView_small")%>" onclick="small()" ></td>
	 <td width="25%"><input type="button" id="back" name="back" value="<%=I18NTools.getString("com.synchroflow.frame.resource","jpgView_back")%>" onclick="window.location.reload();" ></td>

    </tr>

  </table>
  
<%}%>


</body>

<script language="JavaScript" >  

function small(){ 
	//document.all("small").disabled=true;
	//document.all("big").disabled=false;
	var height1=images1.height            
	var width1=images1.width            
	images1.height=height1/1.05        
	images1.width=width1/1.05
	var obj=document.all("sss");
	var sublen=obj.children.length;
	//alert("sublen="+sublen);
	for(i=0;i<sublen;i++){
		//alert("for");
		var subobj=obj.children(i);
		var strCoords=subobj.coords;
		var aaray=strCoords.split(",");
		//alert(aaray.length);
		//alert("1----"+aaray);
		for( j=0;j<aaray.length;j++){
			aaray[j]=aaray[j]/1.05;
			var s=aaray.join(",");
			subobj.coords=s;
		}
		//alert("2---"+subobj.coords);
		//alert(aaray.join(","));
		//alert(s);
		//alert(subobj.coords);
	}
	//alert(subobj);  
	//alert("subojb.shape="+subobj.coords);
}  
function big(){    
	//document.all("big").disabled=true;
	//document.all("small").disabled=false;
	var height1 = images1.height;
	var width1 = images1.width;
	images1.height=height1*1.05;        
	images1.width=width1*1.05;
	var obj=document.all("sss");
	var sublen=obj.children.length;
	for(i=0;i<sublen;i++){
		var subobj=obj.children(i);
		var strCoords=subobj.coords;
		var aaray=strCoords.split(",");
		//alert(aaray.length);
		//alert("1----"+aaray);
		for(j=0;j<aaray.length;j++){
			aaray[j]=aaray[j]*1.05;
			var s=aaray.join(",");
			subobj.coords=s;
		}
		//alert("2---"+subobj.coords);
	}
}             
</script>   
<SCRIPT LANGUAGE="JavaScript">
<!--
function viewDescription(desc){
var dec = desc;
	document.myForm.description.value=dec;
	document.myForm.action="description.jsp";
	document.myForm.submit();
	//alert(document.myForm.description.value);
}  
//-->
</SCRIPT>


</html>